package fybug.nulll.pdstream.IO;
import com.sun.istack.internal.NotNull;
import com.sun.istack.internal.Nullable;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.OutputStream;

import fybug.nulll.pdstream.IO.Stream.CopyByte;
import fybug.nulll.pdstream.IO.Stream.Input;
import fybug.nulll.pdstream.IO.Stream.Output;
import fybug.nulll.pdstream.Source.StreamSource;
/**
 * <h2>字节流操作器构造工场.</h2>
 * <pre>
 * 可以使用 <b>路径</b> 创建操作器，但需要你自己处理{@link FileNotFoundException}
 * 包含:
 * {@link #reader(InputStream...)} 构造读取器
 * {@link #writer(OutputStream, byte[])} 构造写入器
 * {@link #copy(OutputStream, InputStream)} 构造复制器
 * </pre>
 *
 * @author fybug
 * @version 0.0.6
 * @see Input
 * @see CopyByte
 * @see Output
 * @see StreamSource.Bytes
 * @since JDK 1.8
 */
@SuppressWarnings( "all" )
public final
class I_O {
    /** {@Hide} */
    @Deprecated
    private
    I_O() {}

    /*
     * Read
     */

    /** <p>构造一个字节流读取器.</p> */
    @NotNull
    public static
    Input reader(@Nullable final InputStream... reader)
    { return new Input(StreamSource.Bytes.reader(reader)); }

    /** <p>构造一个文件读取器.</p> */
    @NotNull
    public static
    Input reader(@Nullable final File... file) throws FileNotFoundException
    { return new Input(StreamSource.Bytes.reader(file)); }

    /*
     * Write
     */

    /**
     * <p>构造一个字节流写入器.</p>
     * <p>需传入要写入的字节数据</p>
     */
    @NotNull
    public static
    Output writer(@Nullable final OutputStream writer, @Nullable final byte[] s)
    { return new Output(StreamSource.Bytes.writer(writer, s)); }

    /**
     * <p>构造一个字节流写入器.</p>
     * <p>需传入要写入的字节数据</p>
     */
    @NotNull
    public static
    Output writer(@Nullable final OutputStream[] writer, @Nullable final byte[] s)
    { return new Output(StreamSource.Bytes.writer(writer, s)); }

    /**
     * <p>构造一个文件写入器.</p>
     * <p>需传入要写入的字节数据</p>
     */
    @NotNull
    public static
    Output writer(@Nullable final File writer, @Nullable final byte[] s)
    throws FileNotFoundException
    { return new Output(StreamSource.Bytes.writer(writer, s)); }

    /**
     * <p>构造一个文件写入器.</p>
     * <p>需传入要写入的字节数据</p>
     */
    @NotNull
    public static
    Output writer(@Nullable final File[] writer, @Nullable final byte[] s)
    throws FileNotFoundException
    { return new Output(StreamSource.Bytes.writer(writer, s)); }

    /*
     * Copy
     */

    /**
     * <p>构造一个字节流复制器.</p>
     * <p>需传入被复制流</p>
     */
    @NotNull
    public static
    CopyByte copy(@Nullable final OutputStream copyto, @Nullable final InputStream copyfrom)
    { return new CopyByte(StreamSource.Bytes.copy(copyto, copyfrom)); }

    /**
     * <p>使用一个字节组作为被复制源构造一个字节流复制器.</p>
     * <p>需传入被复制流</p>
     */
    @NotNull
    public static
    CopyByte copy(@Nullable final OutputStream copyto, @Nullable final byte[] copyfrom)
    { return new CopyByte(StreamSource.Bytes.copy(copyto, new ByteArrayInputStream(copyfrom))); }

    /**
     * <p>构造一个字节流复制器.</p>
     * <p>需传入被复制流</p>
     */
    @NotNull
    public static
    CopyByte copy(@Nullable final OutputStream[] copyto, @Nullable final InputStream[] copyfrom)
    { return new CopyByte(StreamSource.Bytes.copy(copyto, copyfrom)); }

    /**
     * <p>使用一个字节组作为被复制源构造一个字节流复制器.</p>
     * <p>需传入被复制流</p>
     */
    @NotNull
    public static
    CopyByte copy(@Nullable final OutputStream[] copyto, @Nullable final byte[] copyfrom)
    {
        return new CopyByte(StreamSource.Bytes.copy(copyto, new InputStream[]{
                new ByteArrayInputStream(copyfrom)}));
    }
}
